package top.zy.service.zymallgoodsservice.category.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import top.zy.common.zymallcommon.utils.constants.CacheConstants;
import top.zy.service.zymallgoodsinterface.entity.Category;
import top.zy.service.zymallgoodsservice.category.dao.CategoryMapper;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: HouZeYu
 * @Description:
 * @Date: Created in 15:20 2019/6/19
 */
@Service
public class CategoryServiceImpl implements CategoryService{

    @Autowired
    private CategoryMapper categoryMapper;

    @Cacheable(value = CacheConstants.CACHE_GOODS_CATEGORY,key = "#p0")
    @Override
    public List<Category> queryCategoryListByPid(Long pid) {
        return categoryMapper.selectCategoryListByPid(pid);
    }

    @Cacheable(value = CacheConstants.CACHE_GOODS_CATEGORY_BRANDID,key = "#p0")
    @Override
    public List<Category> queryCategoryListByBrandId(Long brandId) {
        List<Category> categoryList=new ArrayList<>();
        List<Long> categoryIdList=categoryMapper.selectCategoryIdByBrandId(brandId);
        for (Long cid:categoryIdList) {
               Category category=categoryMapper.selectByPrimaryKey(cid);
               categoryList.add(category);
        }
        return categoryList;
    }
    @Cacheable(value = CacheConstants.CACHE_GOODS_CATEGORY_IDS,key = "#p0")
    @Override
    public List<Category> queryCategoryListByIds(List<Long> ids) {
        return categoryMapper.selectCategoryListByIds(ids);
    }
}
